/**
 * Created by aa on 2016/5/25.
 */
$(function () {
    var domOperate = new DomOperation();
    domOperate.bindEvent();
    domOperate.bindUsers();
    domOperate.getScore(function(result){
        $('#myScore').html(result);
    });
    if(domOperate.isOver()){
        location.href='activityend.html';
    }

});

function DomOperation() {
    var dataOperate = new DataOperation();
    //判断活动时候过期
    this.isOver=function(){
        var now=new Date();
        var endDate=dataOperate.getActivityInfo().end;
        endDate=new Date(Date.parse(endDate));
        if(now>endDate){
            return true;
        }
        else{
            return false;
        }
    };
    //绑定前五个用户
    this.bindUsers=function(){
       /* var template = _.template($('#usersTemp').html());
        $('#userList').append(template(JSON.parse(dataOperate.getUsers())));*/

        dataOperate.getUsers(function(result){
            var template = _.template($('#usersTemp').html());
            $('#userList').append(template({users:result}));
        });
    };
    //绑定事件
    this.bindEvent=function(){
        /*$('#share').on('click', function (event) {
            if (browser.versions.iPhone) {
                iosShare('activityshare.html')
            }
        });*/
        $('#getMyCard').on('click', function (event) {
           location.href='activity.html?userid='+wxUtils.getParamsByUrl('userid')+'&v201606160020369';
        });
    };
    //获取积分
    this.getScore=function(callback){
        dataOperate.getScore(callback);
    };
}

//安卓终端做跳转接受拦截
function share(url){
    if (browser.versions.android) {
        location.href=url;
    }
}
